package com.Studen.controller;



import com.Studen.Dao.LoginDaoMpl;
import com.Studen.bean.User;
import com.Studen.servlet.DDLServlet;
import com.Studen.servlet.DDLServletMpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/mainSelect")
public class SelectController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         *  1、设置编码 防止乱码
         *  2、把数据提交到servlet层进行逻辑判断
         *  3、获取前台的管理员id
         * */

        request.setCharacterEncoding("UTF-8");
        String str = request.getParameter("date");
        String adm=request.getParameter("id");
        DDLServlet servletMpl = new DDLServletMpl();
        List<User>admU=servletMpl.getamd(adm);
        List<User> show = new LoginDaoMpl().show();
        DDLServlet servletMpl1 = new DDLServletMpl();
        List<User> list = servletMpl1.Select(str);
        request.setAttribute("u",admU);
        if (list==null){
            request.setAttribute("user", show);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        }
        else {
            request.setAttribute("user", list);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        }
    }
}
